$(function() {
    $('form').parsley();
    getAllOrg();
    dynamicBinding();

});
//遍历所有org输出到表格
function getAllOrg() {
    let deleteStr = "";
    let updateStr = "";
    let columns = [
        {title: "序号", data: null,"render": function (data,type,row,meta) {
                return data=Number(meta.row)+Number(1);
            }},
        {title: "管理操作", data: "operate"},
        {title: "操作", data: "id","orderable": false, // 禁用排序
            "defaultContent": "","render": function (data,type,row,meta) {
                if (hasDeletePermission) {
                    deleteStr = "<button data-id=" + data + "  type='button' class='btn btn-danger data-delete'>删除</button>&emsp;"
                }
                if (hasUpdatePermission) {
                    updateStr = "<button data-id=" + data + " type='button' class='btn btn-info data-update' data-toggle='modal' data-target='#updateOrgModal'>更新</button>";
                }
                return data = deleteStr+updateStr;}}
    ];
    let url ='org/getAllOrg';
    dataTableInit(url,columns);
}
//动态绑定

function dynamicBinding() {
    //为所有的delete按钮绑定delete事件
    deleteBind('/org/deleteOrg');
    //为所有的update按钮绑定update事件
    updateBind("#toUpdateOrg","/org/updateOrg",false,false,"#updateOrgModal");
    //为add按钮绑定add事件
    addBind("#toAddOrg","/org/addOrg",false,false,"#addOrgModal");

    //为update模态框绑定消失事件-清空模态框中内容
    $('#addOrgModal').on('hidden.bs.modal', function () {
        $("#toAddOrg")[0].reset();
    });
    //为update模态框绑定消失事件-清空模态框中内容
    $('#updateOrgModal').on('hidden.bs.modal', function () {
        $("#toUpdateOrg")[0].reset();
    });

}
